
#include "CPerson.h"
#include "CCommand.h"
#include <iostream> 

using namespace std;


void printProgramInfo();


int main()
{
    printProgramInfo();
  
  
    CPerson wilma("Wilma", CCommand());
    CPerson betty("Betty", CCommand(&wilma, &CPerson::listen));
    CPerson barney("Barney", CCommand(&betty, &CPerson::gossip));
    CPerson fred("Fred", CCommand(&barney, &CPerson::passOn));

    fred.talk();
}


void printProgramInfo()
{
    cout    << endl
            << "----------------------------------------------------------------------"         << endl
            << "This program is implemented using the command design pattern."                  << endl
            << endl
            << "1. Create a class that encapsulates some number of the following: "             << endl
            << "   - a 'receiver' object"                                                       << endl
            << "   - the method to invoke"                                                      << endl 
            << "   - the arguments to pass"                                                     << endl
            << "2. Instantiate an object for each 'callback'"                                   << endl
            << "3. Pass each object to its future 'sender'"                                     << endl
            << "4. When the sender is ready to callback to the receiver, it calls execute()"    << endl
            << endl
            << "-> Fred starts to talk()..."                                                    << endl
            << "-> Fred will 'execute' Barney which will result in a call to passOn()"          << endl
            << "-> Barney will 'execute' Betty which will result in a call to gossip()"         << endl
            << "-> Betty will 'execute' Wilma which will result in a call to listen()"          << endl
            << "----------------------------------------------------------------------"         << endl;
}
